= simple_form_for @user do |f|
  = hidden_field_tag :organ_id, @organ.id
  = input f, :name
  = input f, :account
  = input f, :office_phone
  = input f, :mobile_phone
  = input f, :password if @user.id.blank?

  .control-group
    label.control-label for="user_organ" 所属组织
    .controls          
      input id="user_organ" type="hidden" name="user_organ"  


  = input f, :jobs, :collection => Job.all, :input_html => { :multiple => true, :'data-placeholder' => "请选择岗位..." }

  .control-group
    label.control-label for="is_admin" 系统角色
    .controls
      - member = Member.where(:user_id => @user.id, :organ_id => @organ.id).first || Member.new
      - if current_user.super_user?
        = radio_button_tag "is_admin", 2, member.super_admin?
        span 超级管理员

      = radio_button_tag "is_admin", 1, member.admin?
      span 管理员

      = radio_button_tag "is_admin", 0, member.is_admin == 0
      span 成员

  .control-group
    label.control-label for="is_visible_leader" 可见领导组
    .controls
      - member = Member.where(:user_id => @user.id, :organ_id => @organ.id).first || Member.new
      = radio_button_tag "is_visible_leader", 1, member.visible_leader?
      span 可见

      = radio_button_tag "is_visible_leader", 0, member.is_visible_leader == 0
      span 不可见

  = input f, :office_address
  = input f, :sort
  - Property.enabled_properties.each do |p|
    .control-group
      label.control-label = p.name
      .controls
        input name="user_properties[#{p.key}]" type="text" value="#{@user.properties[p.key]}"

  = input f, :comment, :as => :text, :input_html => { :rows => 5 }

  .form-actions
    button.btn.btn-success type="submit" 保存

javascript:
  $(function(){
    var preselect = "#{(@organ.ancestors << @organ).map(&:name).join(',')}";
    var selector = $("#user_organ");
    $.getJSON("#{url_for_event(:organs, :source => :organ_tree)}", function(data){
      selector.optionTree(data, {
        set_value_on: 'each',        
        preselect: {"user_organ": preselect.split(",")},  
        choose: '-- 请选择 --'
      }).change(function(){
        console.log(this.value);
        selector.val(this.value);
      });
      // init input data 
      selector.val("#{@organ.name}")
    });

    $("select").chosen({width: "100%", inherit_select_classes: true});
  })
